package com.agricultural.emergency;

import com.agricultural.equipment.AgriculturalEquipment;

public class ObstacleHandler implements EmergencyHandler {
    private EmergencyHandler nextHandler;

    public ObstacleHandler(EmergencyHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleEmergency(AgriculturalEquipment equipment, String emergencyType) {
        if ("obstacle".equalsIgnoreCase(emergencyType)) {
            System.out.println("处理障碍物紧急情况: " + equipment.getEquipmentId());
            equipment.stop();
            equipment.moveTo(new double[]{equipment.getPosition()[0] + 5, equipment.getPosition()[1]});
            System.out.println(equipment.getEquipmentId() + " 已避开障碍物");
        } else if (nextHandler != null) {
            nextHandler.handleEmergency(equipment, emergencyType);
        }
    }
}    